<?php
namespace Common\Util;

use Common\Model\UserCardListModel;
use Common\Model\UserScoreModel;

class UserData{

	/**
	 * 根据用户ID获取用户信息
	 *
	 * @param $user_id
	 * @return array|mixed
	 */
	public static function getUserInfoById($user_id, $field = ''){
		$t_user = M("user");
		$user_id = intval($user_id);
		if(!$user_info = $t_user->where("id=$user_id")->find()){
			return false;
		}
		$user_info = self::userInfoFormat($user_info);
		if(!empty($field)){
			return $user_info[$field] ? $user_info[$field] : '';
		}
		$card = new UserCardListModel();
		$card_find = $card->getInfo(['user_id' => $user_info['id']]);
		if($card_find){
			$user_info['c_weixin'] = $card_find['c_weixin'];
		}else{
			$user_info['c_weixin'] = '';
		}
		$user_info['add_time'] = date("Y-m-d H:i:s", $user_info['add_time']);
		return $user_info ? $user_info : false;
	}






	/**
	 * 格式化用户信息
	 */
	public static function userInfoFormat($user_info = []){
		if(empty($user_info) || empty($user_info['id'])) return [];
		$user_info['user_headimg'] = $user_info['user_headimg'] ? $user_info['user_headimg'] : "http://xcx.tfxiaochengxu.com/2018-06-15_5b235fa500726.png";
		return $user_info;
	}





}
